<template>
  <div class="setting">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>数据汇总</span>
          <!-- <el-select
            v-model="type"
            class="m-2"
            placeholder="Select"
            style="width: 140px; margin-left: 20px"
            @change="changetype"
          >
            <el-option label="平均分一" :value="0" />
            <el-option label="平均分二" :value="1" />
          </el-select> -->
          <el-button type="primary" style="float: right" @click="winopen"
            >导出</el-button
          >
        </div>
      </template>
      <!-- <div v-for="o in 4" :key="o" class="text item">{{ 'List item ' + o }}</div> -->

      <el-table
        v-if="tableData.value?.length > 0"
        :data="tableData.value"
        border
        style="width: 100%; height: calc(100vh - 250px)"
      >
        <el-table-column
          prop="edu_sort"
          label="教育厅序号"
          sortable
          width="180"
        />
        <el-table-column
          prop="match_sort"
          label="比赛序号"
          sortable
          width="180"
        />
        <el-table-column prop="school" label="学校"> </el-table-column>
        <el-table-column prop="total_fraction_5" label="技能测试" />
        <el-table-column prop="total_fraction_6" label="综合表演" />
        <el-table-column label="总分">
          <template #default="scope">
            {{ fractionTotal(scope.row) }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { scoreList, summary, all_score, del_rater } from "../../api/api";
import { ElMessage } from "element-plus";
let type = ref(0);

let tableData = reactive({ value: [] });

const gettable = () => {
  all_score({ bool: type.value }).then((res) => {
    tableData.value = res.data;
  });
};
gettable();

let dialogVisible = ref(false);
let form = reactive({ name: "" });
let formid = ref(0);

const winopen = () => {
  summary({ bool: type.value }).then((res: any) => {
    console.log(res);
    const blob = new Blob([res]);
    const linkNode = document.createElement("a");
    linkNode.download = "分数汇总.xlsx";
    linkNode.style.display = "none";
    linkNode.href = URL.createObjectURL(blob); //生成一个Blob URL
    document.body.appendChild(linkNode);
    linkNode.click(); //模拟在按钮上的一次鼠标单击
    URL.revokeObjectURL(linkNode.href); // 释放URL 对象
    document.body.removeChild(linkNode);
  });
};

const fractionTotal = (row: any) => {
  let model1 = row.total_fraction_5 ? Number(row.total_fraction_5) : 0;
  let model2 = row.total_fraction_6 ? Number(row.total_fraction_6) : 0;
  let model1num = model1 * 1000000000;
  let model2num = model2 * 1000000000;
  let total = (model1num + model2num) / 1000000000;
  return total;
};

const changetype = () => {
  gettable();
};
</script>

<style lang="less" scoped>
.setting {
  // background: white;
  // padding: 30px;
  .el-card {
    min-height: calc(100vh - 104px);
  }
}
</style>
